package carassius.BLL;

import java.util.GregorianCalendar;

/**
 *
 * @author siebz0r
 */
public class DateTimeHelper
{
	/**
	 * Takes a date and strips off all fields smaler than a day.
	 * This leaves only YEAR, MONTH and DAY set.
	 * The Time will be set at noon (0:0:0:0 PM).
	 * @param date - the date in milliseconds from the epoch
	 * @return - date(year, month, day) in milliseconds
	 */
	public static long stripTime(long date)
	{
		GregorianCalendar cal = new GregorianCalendar(0, 0, 0);
		cal.setTimeInMillis(date);
		cal.clear(GregorianCalendar.HOUR_OF_DAY);
		cal.clear(GregorianCalendar.MINUTE);
		cal.clear(GregorianCalendar.SECOND);
		cal.clear(GregorianCalendar.MILLISECOND);
		return cal.getTimeInMillis();
	}

	/**
	 * @see #stripTime(long)
	 * @param date - the date to be stripped
	 * @return - date(year, month, day) in milliseconds
	 */
	public static long stripTime(GregorianCalendar date)
	{
		return stripTime(date.getTimeInMillis());
	}

	public static boolean compareDates(GregorianCalendar a, GregorianCalendar b)
	{
		return (a.get(GregorianCalendar.DATE) == b.get(GregorianCalendar.DATE)
				&& a.get(GregorianCalendar.MONTH) == b.get(GregorianCalendar.MONTH)
				&& a.get(GregorianCalendar.YEAR) == b.get(GregorianCalendar.YEAR));
	}
}
